package dm71.espil.REST.Tasks;

import dm71.espil.REST.DataService;
import dm71.espil.REST.LoginParameters;
import dm71.espil.activities.FriendListActivity;
import dm71.espil.activities.ListAllUsersActivity;
import dm71.espil.activities.LoginActivity;
import dm71.espil.models.User;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

/**
 * TODO Put here a description of what this class does.
 *
 * @author Moulde.
 *         Created Dec 22, 2011.
 */
public class LoadUsersTask extends AsyncTask<String, Object, User[]>
{
	private ProgressDialog dialog;
	protected Context applicationContext;
	protected ListAllUsersActivity callingActivity;
	
	public LoadUsersTask(ListAllUsersActivity activity)
	{
		this.applicationContext = activity.getApplicationContext();
		this.callingActivity = activity;
	}
	
	@Override
	protected void onPreExecute()
	{
		this.dialog = ProgressDialog.show(callingActivity, "Henter data", "Vent venligst...", true);
	}

	protected User[] doInBackground(String[] params) 
	{
		Log.i("ESPIL", "DoInBackground load users");
		DataService ds = new DataService();
		return ds.getAllUsers(params[0]);
	}
	
	protected void onPostExecute(User[] result) 
	{
		this.dialog.cancel();
		callingActivity.LoadUsersCompleted(result);
	}
}
